﻿using System;
using System.Windows.Data;

namespace XmlStudio.Converters {
    public class TextTrimConverter : IValueConverter {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            var text = value as string;
            int length;
            if(int.TryParse(parameter.ToString(), out length)) {
                if(text != null && length < text.Length) {
                    return string.Format("{0}...", text.Substring(0, length));
                }
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            return value;
        }
        #endregion
    }
}